<template>
  <a-modal :visible="visible" title="详细盘点结果" width="1352px" :footer="null" @cancel="handleCancel">
    <a-tabs class="!-mt-6 !mb-6" v-model:activeKey="state.activeKey">
      <a-tab-pane key="1" tab="异常数据">
        <DynamicTable :tables="dyTable" :config="dyTableConfig" :icons="dyIcons" />
      </a-tab-pane>
      <a-tab-pane key="2" tab="正常数据">
        <DynamicTable :tables="dyNormalTable" :config="dyNormalConfig" :icons="dyNormalIcons" />
      </a-tab-pane>
    </a-tabs>
  </a-modal>
</template>

<script lang="ts" setup>
import { reactive } from 'vue';
import { DynamicTable } from '@/components/public-template';
import indexService from './inventoryResult.service';
import { Api } from '@/config/api/archivesFileInventory';

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  showId: {
    type: String,
    default: ''
  }
});
const emit = defineEmits(['update:visible']);
const state = reactive({
  activeKey: '1'
});
const dyTableConfig: any = {
  queryUrl: Api.inventoryExceptionList,
  protType: 'post',
  scroll: { x: 1200 },
  params: {
    id: props.showId
  },
  beforeWithMethod: (data) => {
    if (!Array.isArray(data)) return null;
    return data.map((item) => ({
      ...item,
      storageLocationCode: item.archivesFileList.storageLocationCode,
      filesBoxCode: item.archivesFileList.filesBoxCode,
      name: item.archivesFileList.name,
      code: item.archivesFileList.code,
      fileCode: item.archivesFileList.fileCode,
      filePages: item.archivesFileList.filePages,
      retentionPeriodDate: item.archivesFileList.retentionPeriodDate
    }));
  }
};
const dyNormalConfig: any = {
  queryUrl: Api.inventoryFileList,
  protType: 'post',
  scroll: { x: 1200 },
  params: {
    id: props.showId
  },
  beforeWithMethod: (data) => {
    if (!Array.isArray(data)) return null;
    return data.map((item) => ({
      ...item,
      storageLocationCode: item.archivesFileList.storageLocationCode,
      filesBoxCode: item.archivesFileList.filesBoxCode,
      name: item.archivesFileList.name,
      code: item.archivesFileList.code,
      fileCode: item.archivesFileList.fileCode,
      filePages: item.archivesFileList.filePages,
      retentionPeriodDate: item.archivesFileList.retentionPeriodDate
    }));
  }
};
const dyTable: any = reactive(indexService.getTables());
const dyNormalTable: any = reactive(indexService.getNormalTables());
const dyIcons: any = reactive(indexService.getIcons(props.showId));
const dyNormalIcons: any = reactive(indexService.getNormalIcons(props.showId));
function handleCancel() {
  emit('update:visible', false);
}
</script>

<style lang="less" scoped></style>
